package com.wanlian.util;

import java.util.ArrayList;
import java.util.List;

public class ListUtil<T> {

    private List<T> list;

    public ListUtil(List<T> list) {
        this.list = list;
    }

    /**
     * 弹出目标个数
     *
     * @param count
     * @return
     */
    public synchronized List<T> deQueue(int count) {
        if (list.size() < count) {
            count = list.size();
        }
        List<T> tagList = new ArrayList<>(count);
        for (int i = 0; i < count; i++) {
            tagList.add(list.get(i));
        }
        this.remove(0, count);
        return tagList;
    }

    /**
     * 移除目标个数
     *
     * @param index
     * @param count
     */
    public void remove(int index, int count) {
        for (int i = index + count - 1; i >= 0; i--) {
            list.remove(i);
        }
    }

}
